<template>
  <div class="login">
    <el-form ref="form" class="form" :model="form" :rules="rules">
      <img class="logo" src="@/assets/common/login-logo.png" alt="">
      <el-form-item prop="mobile">
        <el-input
          v-model="form.mobile"
          prefix-icon="el-icon-user-solid"
          placeholder="请输入内容"
        />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="form.password"
          show-password
          prefix-icon="el-icon-lock"
          placeholder="请输入密码"
        />
      </el-form-item>
      <el-form-item>
        <el-button class="btn" type="primary" @click="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { login } from '@/api/login'
export default {
  data() {
    return {
      form: {
        mobile: '13800000003',
        password: '123456'
      },
      rules: {
        mobile: [
          {
            required: true,
            message: '必填',
            trigger: 'change'
          },
          {
            pattern: /^1[3,9]\d{9}$/,
            message: '请正确输入手机号',
            trigger: 'change'
          }
        ], //  string  必须    手机号
        password: [
          {
            required: true,
            message: '必填',
            trigger: 'change'
          },
          {
            min: 6,
            max: 12,
            message: '请输入6-12位密码',
            trigger: 'change'
          }
        ] //  string  必须    密码
      }
    }
  },
  methods: {
    submit() {
      this.$refs.form.validate(async(result) => {
        if (result) {
          const res = await login(this.form)
          this.$store.commit('user/SETTOKEN', res.data)
          this.$message.success('登录成功')
          this.$router.push('/')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  height: 100%;
  background: url('~@/assets/common/login.jpg') no-repeat;
  background-size: cover;
  justify-content: center;
  align-items: center;
  .form {
    height: 400px;

    .logo {
      padding: 0 15px 20px 15px;
    }
    .btn {
      width: 100%;
      height: 55px;
      font-size: 22px;
    }
    ::v-deep .el-input__inner {
      height: 50px;
    }
  }
}
</style>
